package com.junjie.controller;

import com.alibaba.fastjson.JSONObject;
import com.junjie.entity.ERInformation;
import com.junjie.services.ERInformationService;
import com.junjie.utils.CommonParams;
import com.junjie.utils.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

//员工房间连接信息表
@Controller
@RequestMapping("/erInformation")
@ResponseBody
public class ERInformationController {

    @Autowired
    private ERInformationService erInformationService;

    //根据 id 或 e_id 或 r_id 来查询信息
    @RequestMapping(value = "/selectERInformationByIdOreIdOrrId", method = RequestMethod.GET)
    public CommonResult selectERInformationByIdOreIdOrrId(@RequestParam(value = "id", required = false) Integer id,
                                                          @RequestParam(value = "e_id", required = false) Integer e_id,
                                                          @RequestParam(value = "r_id", required = false) String r_id,
                                                          @RequestParam(value = "status", required = false) Integer status) {
        ERInformation erInformation = new ERInformation();
        erInformation.setId(id);
        erInformation.setEId(e_id);
        erInformation.setRId(r_id);
        erInformation.setStatus(status);
        return new CommonResult(CommonParams.SUCCESS, "查询成功！", erInformationService.selectERInformationByIdOreIdOrrId(erInformation));
    }

    //插入一条员工房间连接信息表
    @RequestMapping(value = "/insertERInformation", method = RequestMethod.POST)
    public CommonResult insertERInformation(@RequestBody JSONObject params) {
        ERInformation erInformation = new ERInformation();
        erInformation.setEId(params.getInteger("e_id"));
        erInformation.setApplyStatus(params.getInteger("apply_status"));
        erInformation.setRId(params.getString("r_id"));
        erInformation.setApt_id(params.getString("apt_id"));
        erInformation.setReasonLog(params.getString("reason_log"));
        erInformation.setStatus(params.getInteger("status"));
        return erInformationService.insertERInformation(erInformation);
    }

    //修改一条数据的方法
    @RequestMapping(value = "/updateERInformation", method = RequestMethod.POST)
    public CommonResult updateERInformation(@RequestBody JSONObject params) {
        ERInformation erInformation = new ERInformation();
        erInformation.setId(params.getInteger("id"));
        erInformation.setEId(params.getInteger("e_id"));
        erInformation.setApplyStatus(params.getInteger("apply_status"));
        erInformation.setRId(params.getString("r_id"));
        erInformation.setApt_id(params.getString("apt_id"));
        erInformation.setReasonLog(params.getString("reason_log"));
        erInformation.setStatus(params.getInteger("status"));
        return erInformationService.updateERInformation(erInformation);
    }

    //删除一条数据的方法
    @RequestMapping(value = "/deleteERInformation/{id}", method = RequestMethod.POST)
    public CommonResult deleteERInformation(@PathVariable("id") Integer id) {
        return erInformationService.deleteERInformation(id);
    }
}
